﻿<%@ WebHandler Language="C#" Class="insertProj" %>

using System;
using System.Web;
using System.Data.OleDb;
using System.Data;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Web.Security;
using System.Text;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text.RegularExpressions;

public class insertProj : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {

        //指定接收数据的类型(解包)
        context.Response.ContentType = "application/json";
        //接收数据(存入变量)
        string user = context.Request["user"],
        title = context.Request["title"],
        url = context.Request["url"];

        int result = insertData(user, title, url);

        context.Response.Write(result);
    }

    public int insertData(string user, string title, string url)
    {

        try
        {
            string Pattern = @"(/(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/g)";
            Regex regex = new Regex(Pattern);
            if (regex.IsMatch(url))
            {
                return 0;
            }
            if (user == "")
            {
                return 0;
            }
            if (title == "")
            {
                return 0;
            }
            

            string inserSql = String.Format(" insert into web(webname,link,maker) " +
                " values('{0}','{1}','{2}') ",
                title, url, user);
            return DBHelper.sqlMethodNoDataset(inserSql);
        }
        catch (Exception e)
        {
            return 0;
        }
    }
    public bool IsReusable {
        get {
            return false;
        }
    }

}